// pages/tabs/home/home.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:[],
    uid:0,
    yinxiao:1
  },
  //播放
  playMusic:function()
  {
    console.log("开启")
    var that=this
    wx.playBackgroundAudio({
      dataUrl: '//downsc.chinaz.net/Files/DownLoad/sound1/201911/12240.wav',
      title: '背景音乐',
      coverImgUrl: 'https://img2.baidu.com/it/u=4233846236,1765599331&fm=253&fmt=auto&app=138&f=JPG?w=500&h=500'
    })
  that.setData({
    yinxiao:1
  })
  },
  //关闭
  stopMusic:function()
  {
    console.log("关闭")
    var that=this
    wx.stopBackgroundAudio()
    that.setData({
      yinxiao:0
    })
  },
  goSimpleGames(){
    wx.navigateTo({
      url: '/pages/games/simpleList/simpleList?game_type=1', 
    })
  },
  goComplexGames(){
    wx.navigateTo({
      url: '/pages/games/complexList/complexList?game_type=2',
    })
  },
  exploreMoreGames(){
    wx.navigateTo({
      url: '/pages/games/simpleList/simpleList',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  getUserInfo:function(uid)
  {

        //获取个人信息
        var that=this
          wx.request({
              url:app.data.service_url + 'Login/getUserInfo',
              data: {
                  uid:uid
              },
              method:"POST",
              header:{
                "Content-Type": "application/x-www-form-urlencoded"
                 },  
                 success(res)
                 {
          console.log("---------------------------------------")
                   console.log(res)
              var  userInfo=res.data.data[0]
                     if(userInfo.openid==""||userInfo.is_login==0)
                     {
                       wx.showToast({
                         title: '请先授权登录',
                         icon:"none",
                         success(res)
                         {
                     
                         }
                       })
                       return false
                     }

                     if(userInfo['yinxiao']=='1')
                     {
                       that.playMusic()
                     }
                    that.setData({
                      userInfo:userInfo,
                      yinxiao:userInfo['yinxiao']
                    })
                 }
            })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
     wx.getStorage({
       key: 'uid',
       success(res)
       {
         var uid=res.data
         that.setData({
           uid:uid
         })
         that.getUserInfo(uid)
       }
     })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})